#include "MotorMsgReporter.h"
#include "SimDriverBoard.h"
#include "DriverModule/DriverManager.h"
#include "DriverModule/ConcreteDriver/Motor.h"

const static std::string MSG_MOTOR_TYPE = "motor";          // 消息类型
const static int MSG_MOTOR_LENGTH = 100;                    // 消息长度
const static int MOTOR_REPORT_10HZ = 50;                    // motor数据的上报频率

MotorMsgReporter::MotorMsgReporter()
{
    SetMsgInfo(MSG_MOTOR_TYPE, MSG_MOTOR_LENGTH);
    SetTimeInterval(MOTOR_REPORT_10HZ);
    m_motorData.clear();
}

bool MotorMsgReporter::Init()
{
    SimDriverBoard& simDriverBoard = SimDriverBoard::Instance();
    m_driverManager = simDriverBoard.GetManager<DriverManager>();
    if (m_driverManager == nullptr) 
    {
        std::cout << "MotorMsgReporter::Init() error   m_driverManager == nullptr" << std::endl;
        return false;
    }

    m_motor1 = m_driverManager->GetDriver<Motor>("motor1");
    m_motor2 = m_driverManager->GetDriver<Motor>("motor2");

    return true;
}

std::string MotorMsgReporter::GetReportMsg()
{
    // TODO：更新报文的数据。
    // update m_motorData;
    // if (m_motor1 != nullptr)
    // {
    //     m_motorData update m1 Speed = m_motor1->GetCurrentSpeed();
    // }
    // if (m_motor2 != nullptr)
    // {
    //     m_motorData update m2 Speed = m_motor2->GetCurrentSpeed();
    // }


    // 报文数据打包
    return m_motorData;
}